import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;



public class chuangti extends JFrame{
    public chuangti(){
        setDefaultCloseOperation(3);//设置关闭方式
        setBounds(650, 200, 500, 500);//设置窗体的位置和大小
        Container c=getContentPane();//获取容器
        c.setLayout(null);//设置布局为绝对布局
        JTextField text=new JTextField();//创建文本框对象
        text.setBounds(50, 60, 180, 35);//设置位置和大小
        c.add(text);//将文本框添加到容器中
        //设置两个按钮
        JButton button1=new JButton("设置");
        JButton button2=new JButton("关闭");
        button1.setBounds(300, 60, 80, 30);
        button2.setBounds(300, 100, 80,30);
        c.add(button1);
        c.add(button2);
        //设置两个标签
        JLabel label1=new JLabel("字体");
        JLabel label2=new JLabel("字号");
        label1.setBounds(70, 100, 50, 50);
        label2.setBounds(160, 100, 50, 50);
        c.add(label1);
        c.add(label2);
        //设置选项按钮
        JRadioButton radiobutton1=new JRadioButton("宋体");
        JRadioButton radiobutton2=new JRadioButton("黑体");
        JRadioButton radiobutton3=new JRadioButton("12");
        JRadioButton radiobutton4=new JRadioButton("18");
        radiobutton1.setBounds(70, 150, 80, 20);
        radiobutton2.setBounds(70, 180, 80, 20);
        radiobutton3.setBounds(160, 150, 80, 20);
        radiobutton4.setBounds(160, 180, 80, 20);
        //确保能够实现单选操作，将不同类型的按钮进行分类
        ButtonGroup group1=new ButtonGroup();
        ButtonGroup group2=new ButtonGroup();
        group1.add(radiobutton1);
        group1.add(radiobutton2);
        group2.add(radiobutton3);
        group2.add(radiobutton4);
        c.add(radiobutton1);
        c.add(radiobutton2);
        c.add(radiobutton3);
        c.add(radiobutton4);
        setVisible(true);//设置窗体可见
        //关闭按钮的监听事件，如果点击此按钮则会直接退出程序
        button2.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);

            }
        });
        //设置按钮的监听事件，来改变文本框中的字体类型和大小
        button1.addActionListener(event->{
            if (radiobutton1.isSelected()&&radiobutton3.isSelected()) {
                text.setFont(new Font("宋体",Font.BOLD,12));
            }
            if (radiobutton1.isSelected()&&radiobutton4.isSelected()) {
                text.setFont(new Font("宋体",Font.BOLD,18));
            }
            if (radiobutton2.isSelected()&&radiobutton3.isSelected()) {
                text.setFont(new Font("黑体",Font.BOLD,12));
            }
            if (radiobutton2.isSelected()&&radiobutton4.isSelected()) {
                text.setFont(new Font("黑体",Font.BOLD,18));
            }
        });
    }
    public static void main(String[] args) {
        new chuangti();
    }

}

